import { Page } from "puppeteer-core";
import { Extractor } from "../class/Extractor";
import { Spider } from "../class/Spider";
import { $text, $eval, $$text, $attr, $$attr, spider } from "../Decorators/Extractor";

export class Extractor1 extends Extractor {

    /**
     * 获得一个 spider 对象
     */
    @spider("book")
    book!: Spider

    /** 多个多个元素的属性(href) */
    @$$attr("body > div.wrap > div.top-two-blank.clearfix > div.top-two-blank-mid.fl > div > div.mind-showbook.clearfix > div > div.book-info.fr > div.bookname > a", "href")
    href: string[] = [];

    static loadHook(pages: Page[]) {
        for (const page of pages) {
            // 禁用 js 脚本
            page.setJavaScriptEnabled(false)
        }
    }


    async handleAfterHook() {
        this.href.forEach((e) => this.book.createTask(e))
        console.log(`书的数量${this.href.length}`);
    }
}



